def lol(x):
    b = 0
    for i in range(2,x):
        if x%i==0:
            b+=1
    if b==0:
        return True
    else:
        return False

a=input()
digital=['zero','one','two','three','four','five','six','seven','eight','nine']
num=a.split()
if len(num)==3: 
    if num[0] in digital and num[0]!='zero' and num[1] in digital and num[2] in digital :
        z=digital.index(num[0])
        x=digital.index(num[1])
        c=digital.index(num[2])
        v=z*100+x*10+c
        for l in range (v, 1, -1):
            if lol(l):
                k=l
                break
        for j in range (v, 999):
            if lol(j):
                p=j
                break
        if ((p-v)>=(v-k)):
            print(k)
        else:
            print(p)



    else:
        print('Wrong input')
else:
    print('Wrong input')
